Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent sitemap.xml from 404ing #91

Merged
merged 2 commits into from
Sep 25, 2021
Merged

Prevent sitemap.xml from 404ing #91

merged 2 commits into from
Sep 25, 2021

Conversation

rebeccahum
Copy link
Contributor

@rebeccahum rebeccahum commented Sep 24, 2021

Reproduction

  • Ensure WP sitemaps is enabled
  • Offload pages to ES:
function page_es_offload( $query ) {

	if ( $query->is_main_query() && $query->is_page() ) { // Conditions to offload to ES.
    	$query->set( 'es', true );
	}
}
add_action( 'pre_get_posts', 'page_es_offload' );
  • Visit /sitemap.xml

Expectation

When Accessing sitemap.xml, it should redirect to wp-sitemap.xml: https://github.com/WordPress/WordPress/blob/5.8.1/wp-includes/sitemaps/class-wp-sitemaps.php#L237

Actual

Accessing sitemap.xml leads to a 404 because it doesn't redirect due to lack of pagename sanitization, as the value ends up being sitemap.xml rather than sitemap-xml: https://github.com/WordPress/WordPress/blob/5.8.1/wp-includes/class-wp-query.php#L2062

Reported: Automattic/vip-go-mu-plugins#2430

@mboynes
Copy link
Contributor

mboynes commented Sep 24, 2021

Thanks for the PR! My only pause is that it’s a relatively heavy hand and could have unintended side effects. I wonder if we should consider a more targeted approach? (checking if the pagename is the sitemap)

@rebeccahum
Copy link
Contributor Author

Yep, that alternative crossed my mind as well!

...I am wondering if there are other use cases where the pagename should be sanitized, but makes sense to start with a smaller umbrella.

@rebeccahum
Copy link
Contributor Author

@mboynes I've added the changes in now.

@mboynes mboynes merged commit 90b9788 into alleyinteractive:main Sep 25, 2021
@mboynes
Copy link
Contributor

mboynes commented Sep 25, 2021

Awesome, thanks @rebeccahum!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants